﻿var state = 0; //0:list 1:picture
function addfolder() {
    var foldername = $("#newfold").val();
    $("#newfold").val("");
    var tag = $("#tag").val();
    $.post("/Group/AddFolder", { "fold": foldername, "tag": tag },
    function (data) {
        if (data == 1) {
            if (state == 0)
                update("0");
            else if (state == 1)
                update("1");
            $.globalMessenger().post("新建文件夹" + foldername + "成功！");
        } else if (data == 0) {
            $.globalMessenger().post({
                message: "文件夹名重复，请重新命名", type: 'error',
                showCloseButton: true
            });
        }
    });
}
function deletef(foldername, tag) {
    $.post("/Group/Delete", { "name": foldername, "tag": tag },
    function (data) {
        if (state == 0) {
            update("0");
        }
        else if (state == 1)
            update("1");
        $.globalMessenger().post(foldername + "删除成功！");
    });
}

function handleUpdate() {
    var json = context.get_data();
    var data = Sys.Serialization.JavaScriptSerializer.deserialize(json);
}
$(function () {
    //上传
    $('#fileInput1').uploadify({
        'uploader': '/Content/uploadify.swf',
        'script': '/Group/Import',
        'folder': '/Content/files',
        'cancelImg': '/Content/cancel.png',
        'sizeLimit': 1024 * 1024 * 10, //10M
        'fileTypeDesc': 'Image Files',
        //允许上传的文件后缀
        'fileTypeExts': '*.gif; *.jpg; *.png; *.JPEG; *.bmp',
        'multi': true,
        'onComplete': fun
    });

});
function fun(event, queueID, fileObj, response, data) {
    if (response == "") {
        $.globalMessenger().post({
            message: "文件上传出错！", type: 'error',
            showCloseButton: true
        });
    } else if (response == "x") {
        $.globalMessenger().post({
            message: "文件名重复！一个文件夹下不能有重复的文件名", type: 'error',
            showCloseButton: true
        });
    } else {
        $.globalMessenger().post("成功上传" + response);
        if (state == 0)
            update('0');
        else if (state == 1)
            update('1');
    }
}
//显示提示信息，textstyle2为绿色，即正确信息；textstyl1为红色，即错误信息
function showInfo(msg, type) {
    var msgClass = type == true ? "textstyle2" : "textstyle1";
    $("#result").removeClass();
    $("#result").addClass(msgClass);
    $("#result").html(msg);
}
//如果点击‘导入文件’时选择文件为空，则提示
function checkImport() {
    if ($.trim($('#fileInput1Queue').html()) == "") {
        alert('请先选择要导入的文件！');
        return false;
    }
    return true;
}